package com.liangzhong.modules.Main.command
{
	import com.common.utils.Debug;
	import com.liangzhong.commandconst.CMD_Lobby;
	import com.liangzhong.commandconst.CMD_NineHalf;
	import com.liangzhong.commandconst.vip.CMD_Vip_NineHalf;
	import com.liangzhong.constants.ApplicationConstants;
	import com.liangzhong.constants.NotificationConstants;
	import com.liangzhong.model.AppData;
	import com.liangzhong.model.lobby.vo.GameTypeConst;
	import com.liangzhong.model.lobby.vo.RoomInfo;
	import com.liangzhong.model.lobby.vo.RoomLevel;
	import com.liangzhong.model.lobby.vo.RoomStatus;
	import com.liangzhong.proxy.lobby.LobbyProxy;
	
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.command.SimpleCommand;

	/**
	 * 游戏房间命令 分析机
	 * @author lxh
	 */	
	public class GameRoomCommand extends SimpleCommand
	{
		public function GameRoomCommand()
		{
			super();
		}
		
		override public function execute(notification:INotification):void
		{
			var lobbyProxy :LobbyProxy = facade.retrieveProxy(LobbyProxy.ProxyName) as LobbyProxy;
			
			var gameType :int ;
			var userId :int = AppData.getInstance().user.userID;
			var roomId :int;
			var retCode :int;
			var roomCountInfos :Array = [];
			switch(notification.getName())
			{
				case ApplicationConstants.Lobby_getGameRooms://请求游戏房间
				{
				}
				case LobbyProxy.GetGameRooms_Result:
				{
					break;
				}
				case ApplicationConstants.Lobby_getGameRoomNumbers://获取在线人数
				{
					break;
				}
				case LobbyProxy.GetGameRoomNumbers_Result:
				{
					break;
				} 
				case ApplicationConstants.Lobby_enterGameRoom://加入房间
				{
					roomId = int(notification.getBody().roomId);
					gameType = notification.getBody().gameType;
					AppData.getInstance().game.currentRoomId = roomId;
					AppData.getInstance().game.currentGameType = gameType;
					lobbyProxy.enterGameRoom(userId,roomId);
					Debug.echo("Lobby -->enter game room req roomId = " + roomId,Debug.TRACER);
					//this.sendNotification(NotificationConstants.Application_Show_Req_Mark);
					break;
				}
				case LobbyProxy.EnterGameRoom_Result:
				{
					/*交易返回码
					0表示成功，非0表示失败
					1：人数已满
					2：余额不够
					3：该用户原来所在的房间游戏没有结束
					101：房间系统错误*/
					retCode = int(notification.getBody());
					Debug.echo("Lobby --> enter game room res RetCode = " + retCode,Debug.TRACER);
					Debug.echo("Lobby --> currentGameType = " + AppData.getInstance().game.currentGameType,Debug.TRACER);
					//this.sendNotification(NotificationConstants.Application_Un_Show_Req_Mark);
					roomId = AppData.getInstance().game.currentRoomId;
					var roomInfo :RoomInfo = AppData.getInstance().game.getRoomInfoByRoomId(roomId);
					switch(retCode)
					{
						case RoomStatus.ROOM_NORMAL://成功
						{
							gameType = AppData.getInstance().game.currentGameType;
							CMD_Lobby.MAIN_Game = AppData.getInstance().game.currentRoomId;
							switch(gameType)
							{
								case GameTypeConst.NINEHALF://九点半
								{
									/*if(roomInfo.grade == RoomLevel.GRADE_0)
									{
										CMD_Vip_NineHalf.MAIN = AppData.getInstance().game.currentRoomId;
										this.sendNotification(NotificationConstants.Server_EnterGameRoom_Vip_Success);
										return;
									}*/
									CMD_NineHalf.MAIN_NineHalf = AppData.getInstance().game.currentRoomId;
									break;
								}
								default :
								{
									this.sendNotification(NotificationConstants.Application_Show_RemindInfo,"未知游戏类型! " + gameType);
									break;
								}
							}
							break;
						}
						case RoomStatus.ROOM_MEMBER_FULL://人数已满
						{
							this.sendNotification(NotificationConstants.Application_Show_RemindInfo,"人数已满");
							break;
						}
						case RoomStatus.ROOM_NO_MONEY://余额不够
						{
							this.sendNotification(NotificationConstants.Application_Show_RemindInfo,"余额不够,请充值!");
							break;
						}
						case RoomStatus.ROOM_GAME_START://该用户原来所在的房间游戏没有结束
						{
							//this.sendNotification(NotificationConstants.Application_Show_RemindInfo,"正在游戏中，等待当前游戏结束后进入");
							break;
						}
						case RoomStatus.ROOM_SYSTEM_ERROR://房间系统错误
						{
							this.sendNotification(NotificationConstants.Application_Show_RemindInfo,"房间系统错误");
							break;
						}
						default:
						{
							this.sendNotification(NotificationConstants.Application_Show_RemindInfo,"未知错误! " + retCode);
							break;
						}
					}
					break;
				}
				case ApplicationConstants.Lobby_SitDown://坐下
				{
					lobbyProxy.sitDown(notification.getBody());
					break;
				}
				case ApplicationConstants.Lobby_leaveGameRoom://离开房间
				{
					roomId = AppData.getInstance().game.currentRoomId;
					Debug.echo("Lobby -->leave game room req RoomId:"+roomId,Debug.TRACER);
					lobbyProxy.leaveGameRoom(userId,roomId);
					this.sendNotification(NotificationConstants.GameRoom_StartRoomCountTimer);
					break;
				}
				case LobbyProxy.leaveGameRoom_Result:
				{
					Debug.echo("Lobby -->leave game room res",Debug.TRACER);
					break;
				}
			}
		}
	}
}